//
//  MGHomeVC.swift
//  weibo
//
//  Created by apple on 2023/7/7.
//  Copyright © 2023 陈明光. All rights reserved.
//

import UIKit

class MGHomeVC: UIViewController {

    var pageViewController:XLPageViewController!

    var titles = ["关注","推荐"]
    override func viewDidLoad() {
        super.viewDidLoad()
        initPageViewController()

    }
    func initPageViewController(){
        let config = XLPageViewControllerConfig.default()
        config.shadowLineColor = UIColor.cz_color(withHex: 0xFF8C00)
        config.titleSelectedFont = UIFont.systemFont(ofSize: 19)
        config.titleNormalFont = UIFont.systemFont(ofSize: 19)
        config.titleViewAlignment = .center
        config.showTitleInNavigationBar = true;
        config.separatorLineHidden = true;
        config.shadowLineAnimationType = .zoom
        config.shadowLineWidth = 35
        
        pageViewController = XLPageViewController.init(config: config)
        pageViewController.view.frame = self.view.bounds
        pageViewController.delegate = self
        pageViewController.dataSource = self
        self.addChild(pageViewController)
        self.view.addSubview(pageViewController.view)
        //默认选中
        pageViewController.selectedIndex = 1
    }
}

extension MGHomeVC:XLPageViewControllerDelegate,XLPageViewControllerDataSrouce{
    func pageViewController(_ pageViewController: XLPageViewController, didSelectedAt index: Int) {
        print("切换到\(titles[index])")
    }
    
    func pageViewController(_ pageViewController: XLPageViewController, viewControllerFor index: Int) -> UIViewController {
        if index == 0 {
            let vc = MGFollowViewController()
            return vc
        }
        let vc = MGChannelManageExampleVC()
        return vc
        
    }
    
    func pageViewController(_ pageViewController: XLPageViewController, titleFor index: Int) -> String {
        return titles[index]
    }
    
    func pageViewControllerNumberOfPage() -> Int {
        return titles.count
    }
}


